﻿$(function () {
    getWarehouseData();
});
var obj = {
    warehouseId: '',
    warehouseNo: '',
    warehouseName: '',
    reservoirArea: '',
    locationCoding: '',
    warehouseArea: '',
    warehouseHead: '',
    warehouseState: '',
    warehouseRemark: '',
    createdBy: '',
    createdDate: '',
    updatedBy: '',
    updatedDate: '',
    deletedBy: '',
    deletedDate: '',
    isDeleted: ''
}

//仓库返填
function getWarehouseData() {
    layui.use(function () {
        var form = layui.form;
        var warehouseId = localStorage.getItem("warehouseId");
        $.ajax({
            url: '/Warehouse/WarehouseBackfill',
            type: 'get',
            data: {
                warehouseId: warehouseId,
                token: localStorage.getItem("token")
            },
            success: function (res) {
                var res = JSON.parse(res)
                console.log(res)
                $.each(res, function () {
                    $("#warehouseNo").text(this.warehouseNo)
                    $("#warehouseName").text(this.warehouseName)
                    $("#reservoirArea").text(this.reservoirArea)
                    $("#locationCoding").text(this.locationCoding)
                    $("#warehouseArea").text(this.warehouseArea)
                    $("#warehouseHead").text(this.warehouseHead)
                    $('#warehouseState').text(this.warehouseState == 1 ? "正常" : "异常")
                    $("#warehouseRemark").text(this.warehouseRemark)
                    $("#createdBy").text(this.createdBy)
                        form.render(); // 重新渲染
                })
            },
        })
    })
    showReservoir();
    showBinLocation();
}


//显示库区根据仓库id
function showReservoir() {
    console.log(localStorage.getItem("warehouseId"))
    layui.use(function () {
        var table = layui.table;

        $.ajax({
            url: '/Warehouse/ReservoirsShowByWarehouseId',
            type: 'get',
            data: {
                pageindex: 1,
                pagesize: 100,
                token: "",
                WarehouseId: localStorage.getItem("warehouseId")
            },
            success: function (data) {
                data = JSON.parse(data);
                console.log(data.data);
                // 在 ajax 请求成功后，使用正确的表格 ID 进行 reload
                table.reload('reservoirTable', {
                    page: {
                        limit: 5,
                        limits: [5, 8, 10]
                    },
                    data: data.data
                });
            },
            error: function (res, msg) {
                console.log(res, msg)
            }
        })
        // 创建渲染实例
        table.render({
            elem: '#reservoirTable',
            page: {
                limit: 5,
                limits: [5, 8, 10]
            },
            cols: [[
                { field: 'reservoirId', width: 100, title: '序号' },
                { field: 'reservoirNo', width: 180, title: '库区编号' },
                { field: 'reservoirName', width: 100, title: '库区名称' },
                { field: 'reservoirArea', width: 100, title: '面积' },
                //{ field: 'binLocationNum', width: 110, title: '库位数量' },
                { field: 'reservoirRemark', width: 100, title: '备注' },
            ]],
            // 初始时可以先不加载数据，等待 ajax 请求成功后再更新
            data: []
        });

    });
}

//显示库位根据库区id
function showBinLocation() {
    console.log(localStorage.getItem("warehouseId"))
    layui.use(function () {
        var table = layui.table;

        $.ajax({
            url: '/Warehouse/BinLocationShowByReservoirId',
            type: 'get',
            data: {
                pageindex: 1,
                pagesize: 100,
                token: "",
                WarehouseId: localStorage.getItem("warehouseId")
            },
            success: function (data) {
                data = JSON.parse(data);
                console.log(data.data);
                // 在 ajax 请求成功后，使用正确的表格 ID 进行 reload
                table.reload('binlocationTable', {
                    page: {
                        limit: 5,
                        limits: [5, 8, 10]
                    },
                    data: data.data
                });
            },
            error: function (res, msg) {
                console.log(res, msg)
            }
        })
        // 创建渲染实例
        table.render({
            elem: '#binlocationTable',
            page: {
                limit: 5,
                limits: [5, 8, 10]
            },
            cols: [[
                { field: 'binLocationId', width: 100, title: '序号' },
                { field: 'binLocationName', width: 100, title: '库位名称' },
                { field: 'binLocationNo', width: 180, title: '库位编号' },
                { field: 'binLocationArea', width: 100, title: '面积' },
                { field: 'maximumLoad', width: 100, title: '最大载重量' }, 
                //{ field: 'reservoirRemark', width: 110, title: '库位数量' },
                { field: 'binLocationNotes', width: 110, title: '备注' },
            ]],
            // 初始时可以先不加载数据，等待 ajax 请求成功后再更新
            data: []
        });

    });
}